//
// Created by shaowenhan on 2020/7/22.
//
#include "ConfigurableEventListener.h"
#include "WriteMDVRPResult.h"
#include "WriteResults.h"
#include "ReadInstanceWrapper.h"
#if defined(MDVRP) or defined(MDOVRP)
TEST(WriteMDVRPResult, WriteMDVRPResult)
{
#if defined(MDVRP)
    Instance instance = {"", "", 2, 3, 15, {0, 0, 2, 3, 5}, {0, 0, 3, 2, 8}, 2, 18,
                         {{0, 1.2, 2.2, 3.5, 2.4},
                          {1.2, 0, 3.1, 2.3, 4.2},
                          {2.2, 3.1, 0, 4.4, 1.2},
                          {3.5, 2.3, 4.4, 0, 5.2},
                          {2.4, 4.2, 1.2, 5.2, 0}}};
#elif defined(MDOVRP)
    Instance instance = {"", "", 2, 3, 15, {0, 0, 2, 3, 5},
                         {{0, 1.2, 2.2, 3.5, 2.4},
                          {1.2, 0, 3.1, 2.3, 4.2},
                          {0, 0, 0, 4.4, 1.2},
                          {0, 0, 4.4, 0, 5.2},
                          {0, 0, 1.2, 5.2, 0}}};
#endif
    Result* res;
    res = obtainResult(false);
    res->initialize();
#if defined(RunModeDebug)
    res->lastImprovementStep = 0;
    res->unImproveSteps.emplace_back(vector<int>{});
#endif
    res->updateBestSol(19.2, 0);
    res->recordBestSol({
                               {0, 2},
                               {0, 3},
                               {1, 4}
                       });
    WriteMDVRPResult::writeMDVRPResult(instance, res, "result.res");
    delete res;
}

TEST(WriteResult, WriteResult)
{
    RunParaAndResult runParaAndResult;
#if defined(MDVRP)
    runParaAndResult.instance = Instance{"", "", 2, 3, 15, {0, 0, 2, 3, 5}, {0, 0, 3, 2, 8}, 2, 18,
                         {{0, 1.2, 2.2, 3.5, 2.4},
                          {1.2, 0, 3.1, 2.3, 4.2},
                          {2.2, 3.1, 0, 4.4, 1.2},
                          {3.5, 2.3, 4.4, 0, 5.2},
                          {2.4, 4.2, 1.2, 5.2, 0}}};
#elif defined(MDOVRP)
    runParaAndResult.instance = Instance{"", "", 2, 3, 15, {0, 0, 2, 3, 5},
                                         {{0, 1.2, 2.2, 3.5, 2.4},
                                          {1.2, 0, 3.1, 2.3, 4.2},
                                          {0, 0, 0, 4.4, 1.2},
                                          {0, 0, 4.4, 0, 5.2},
                                          {0, 0, 1.2, 5.2, 0}}};
#endif
    runParaAndResult.resultFileName = "result";
    Result *res;
    res = obtainResult(false);
    res->initialize();
#if defined(RunModeDebug)
    res->lastImprovementStep = 0;
    res->unImproveSteps.emplace_back(vector<int>{});
#endif
    res->updateBestSol(19.2, 0);
    res->recordBestSol({
                               {0, 2},
                               {0, 3},
                               {1, 4}
                       });
    runParaAndResult.bestRes->record(res);
#if defined(RunModeDebug)
    PenaltyFactor penaltyFactor{ParameterForPenaltyFactor{{1.0, 1.0}, {2.0, 2.0}, {3.0, 3.0}, 4}};
    penaltyFactor.reset();
    runParaAndResult.bestRes->allGenObjFeaCostAndPenaltyPenaltyFactorAndMoveType = {
        {{4.5, true, CostAndPenalty{3}, penaltyFactor, TwoOpt}, {3.2, false, CostAndPenalty{3}, penaltyFactor, Relocate1},
         {4.5, true, CostAndPenalty{3}, penaltyFactor, Relocate1}, {3.2, false, CostAndPenalty{3}, penaltyFactor, Relocate1},
         {4.5, true, CostAndPenalty{3}, penaltyFactor, Relocate1}, {3.2, false, CostAndPenalty{3}, penaltyFactor, Relocate1}},
        {{7.33, true, CostAndPenalty{3}, penaltyFactor, Relocate1}}
    };
    runParaAndResult.bestRes->bestSolAndDeltaAndPercentageComparedWithBestSol = {
            {{4.2, 0.2, 5}, {4, 0, 0}, {4.2, 0.2, 5}, {4, 0, 0}, {4.2, 0.2, 5}, {4, 0, 0}},
            {{4.7, 0, 0}}
    };
#endif
    runParaAndResult.randomSeeds = {5};
    WriteResults::recordResult(runParaAndResult);
    delete res;
}
#endif
